/*
 * @Author: your name
 * @Date: 2021-08-10 20:06:09
 * @LastEditTime: 2021-08-28 15:29:18
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \doctor\src\router\index.js
 */
import Vue from 'vue'
import VueRouter from 'vue-router'
import Login from '../views/Login.vue'
import Coupon from './huang/router'
//引入路径pathArr.js文件
import pathArr from '../router/pathArr.js';
import shopconfiguration from './shopconfiguration';
//导入菜品管理路由
import menMag from './gou/index.js';
//导入库存路由
import stock from './ava/stock.js';
//导入订单路由
import order from './ava/order.js';
//报表
import Dishessales from './zcs/index.js'
import Dishesflow from './zcs/index.js'
import Cashflow from './zcs/index.js'
import Storerevenue from './zcs/index.js'
import Userdata from './zcs/index.js'
// 系统管理
import SystemSet from './tang/index.js'
Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    // name: 'Login',
    redirect:'/login',
    component: Login,
  },
  {
    path: '/login',
    name: 'Login',
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () => import(/* webpackChunkName: "about" */ '../views/Login.vue')
  },
  {
    path:'/main',
    name:'main',
    redirect:'/main/homePage',
    component:()=>import('../views/main.vue'),
    children:[
      ...shopconfiguration,
      ...menMag,
      ...Coupon,
      
      //库存
      ...stock,
      //订单
      ...order,

      //报表
      ...Dishessales,
      ...Dishesflow,
      ...Cashflow,
      ...Storerevenue,

      ...Userdata,
      // 系统设置
      ...SystemSet


    ]
  }

]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})
//全局前置守卫，判断是否有token来判断是否有权限访问主页
 /* router.beforeEach(function(to,from,next){
  if(pathArr.indexOf(to.path)!==-1){//如果能够在路径文件中找到对应的路径
    const token=sessionStorage.getItem('token');//获取token
    // console.log('全局前置守卫',token);
    if(token){//如果存在token  表示已经登录
      next();
    }else{//表示未登录
      next('/login');
    }
  }else{
    next();
  }

}) */


export default router
